#include "Auxiliary.h"
#include "ArgsParser.h"
#include "ASyncConnection.h"
#include "PingPong.h"
#include "SyncConnection.h"


int main(int argc, const char *argv[])
{
	try
	{
		ArgsParser args(argc, argv);
		ServerInfo info(args.GetHostName(), args.getPort());

		if (args.IsPingPongServer())
		{
			PingPong(true); // starts a thread and blocks current
		}
		else
		{
			if (args.IsPingPongClient())
				new PingPong(info, false); // starts a thread only
			Stats::StartStatsPrinter("Results.xml", 60.0, true); //starts new thread (which will print
																 // statistics and terminate program).
			//Starting connections
			if (args.IsSync())
			{
				SyncConnection(info, args.GetConnectionCount()); // starts new threads and blocks current
			}
			else
			{
				ASyncConnection(info, args.GetConnectionCount()); // starts new thread and blocks current
			}
		}
	}
	catch (std::exception &ex)
	{
		printf("Error: %s\n", ex.what());
	}
	return 0;
}
